﻿/*******************************************************************************
#                    ADMCopyRightsBroker.cs
#  Comment:
#
#  Current Version: V1.0
#  Author: 
#
#  History List:
#  V1.0    Created by Onions@2009-8-21 13:08:14
#
#******************************************************************************/
#region Usings
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using SYS.Basic;

using ExpertMIS.Brokers;
using ExpertMIS.Entities;
using System.Collections;
using IBatisNet.Extend;
#endregion

namespace ExpertMIS.Brokers
{
    public class ADMCopyRightsBroker : ExpertMISBaseBroker
    {
        #region Private Methods

        private object UpdateADMCopyRights(IEntity entity)
        {
            return SqlMap.Update("UpdateADMCopyRightsEntity", entity);
        }

        private object InsertADMCopyRights(IEntity entity)
        {
            return SqlMap.Insert("InsertADMCopyRightsEntity", entity);
        }

        private object DeleteADMCopyRights(IEntity entity)
        {
            return SqlMap.Delete("DeleteADMCopyRightsEntity", entity);
        }

        #endregion

        #region Override Methods

        protected override IEntity ProcessGetEntity(System.Collections.Hashtable keys)
        {
            if (!keys.Contains("OID")) throw new Exception("invalid request parameters.");
            return SqlMap.QueryForObject<IEntity>("SelectADMCopyRightsByOID", keys["OID"] as string);
        }

        protected override bool ProcessSaveEntity(IEntity entity, Hashtable request)
        {
            if (entity.EntityState == EntityState.New)
            {
                InsertADMCopyRights(entity);
                entity.EntityState = EntityState.Old;
            }
            else
            {
                UpdateADMCopyRights(entity);
            }

            return true;
        }

        protected override IEntity ProcessNewEntity()
        {
            ADMCopyRightsEntity entity = new ADMCopyRightsEntity();

            // initial entity object

            return entity;
        }

        protected override bool ProcessRemoveEntity(IEntity entity, Hashtable request)
        {
            try
            {
                DeleteADMCopyRights(entity);
                return true;
            }
            catch
            {
                return false;
            }
        }

        #endregion

        /// <summary>
        /// 获取上一次版权信息
        /// </summary>
        /// <returns></returns>
        public ADMCopyRightsEntity GetLastCopyRights()
        {
            return SqlMap.QueryForObject("SelectLastCopyRights", null) as ADMCopyRightsEntity;
        }
    }
}